var Request = GetRequest();
$(function($){
    getInfoById();
});

function getInfoById() {
    $.ajax({
        url: '/hospital/recordReferral/queryById',
        data:{
            'id' : Request.id
        },
        type: 'get',
        dataType: 'json',
        contentType: 'application/json;charset=utf-8',
        cache: false,
        success: function(data) {
            var list = data.result;
            console.log(list);
            setObject(list);
        },
        error: function(xhr) {
        }
    });
}


/**
 *
 * @param form
 */
function setObject(list) {
    for(var item in list){
        if(item == 'patientSex'){
            if(list[item] == 1){
                $sex = '男';
            }else{
                $sex = '女';
            }
            $('#'+ item +'').html($sex);
        }else if(item == 'patientType'){
            if(list[item] == 1){
                $type = '职工';
            }else{
                $type = '居民';
            }
            $('#'+ item +'').html($type);
        }else {
            $('#'+ item +'').html(list[item]);
        }
    }
}


function printFull() {
    $(".footer").hide();
    window.print();
    setTimeout(function(){
        $(".footer").show();
    },200);
}

function colsePrint() {
    var userAgent = navigator.userAgent;
    if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
        location.href = "about:blank";
    } else {
        window.opener = null;
        window.open('', '_self');
    }
    window.close();
}

function doPrint(){

    //判断iframe是否存在，不存在则创建iframe
    var iframe=document.getElementById("print-iframe");
    if(!iframe){
        var el = document.getElementById("printcontent");
        iframe = document.createElement('IFRAME');
        var doc = null;
        iframe.setAttribute("id", "print-iframe");
        iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
        document.body.appendChild(iframe);
        doc = iframe.contentWindow.document;
        //这里可以自定义样式
        //doc.write("<LINK rel="stylesheet" type="text/css" href="css/print.css">");
        doc.write('<div>' + el.innerHTML + '</div>');
        doc.close();
        iframe.contentWindow.focus();
    }
    iframe.contentWindow.print();
    if (navigator.userAgent.indexOf("MSIE") > 0){
        document.body.removeChild(iframe);
    }

}